<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>js数组之累积示例</title>
  <style>
    * { padding:0; margin: 0; }
    body {
      display: flex;
      justify-content: center;
      align-content: center;
      background-color: #34495e;
    }
    div {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      font-size: 5em;
      font-weight: bold;
      text-transform: uppercase;
      color: #9b59b6;
    }
    div > span {
      display: inline-block;
      position: relative;
    }
    .color {
      animation-name: color;
      animation-duration: .8s;
      animation-direction: alternate;
      animation-iteration-count: 2;
      animation-timing-function: linear;
    }
    @keyframes color {
      from {
        color: #f0c40f;
        transform: scale(2);
      }
      to {
        color: #e74c3c;
        transform: scale(.5);
      }
    }
  </style>
</head>
<body>
  <div name="logo">Miracle</div>
  <script>
    const logo = document.querySelector('[name="logo"]')
    Array.from(logo.textContent).reduce((pre, cur, index) => {
      pre === index && (logo.innerHTML = '')
      const span = document.createElement('span')
      span.innerHTML = cur
      span.addEventListener('mouseover', function () {
        this.classList.add('color')
      })
      span.addEventListener('animationend', function () {
        this.classList.remove('color')
      })
      logo.appendChild(span)
    }, 0)
  </script>
</body>
</html>